package com.yiman.framework.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yiman.framework.web.page.PageDomain;
import com.yiman.framework.web.page.TableDataInfo;
import com.yiman.framework.web.page.TableSupport;

import java.util.List;

/**
 * @author: Mr.yang
 * @create: 2019-06-05
 **/
public class BaseController {

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    protected TableDataInfo getDataTable(List<?> list) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setData(list);
        rspData.setCount(new PageInfo(list).getTotal());

        return rspData;
    }

    /**
     * 设置请求分页数据
     */
    protected void startPage() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
    }
}
